﻿namespace Maple.Weixin.MP.Entities.Messages
{
    public class ResponseVideo : ResponseMedia, IResponseService
    {
        private string mediaId;

        internal ResponseVideo() { }

        public ResponseVideo(string mediaId) {
            this.mediaId = mediaId;
        }

        public static ResponseVideo CreateByFile(string fileName, out string result)
        {
            var responseVideo = new ResponseVideo();
            var mediaId = responseVideo.UploadMedia(fileName, out result);
            if (string.IsNullOrEmpty(mediaId))
                return null;
            responseVideo.mediaId = mediaId;
            return responseVideo;
        }

        public ResponseVideo(string mediaId, string title, string description)
            : this(mediaId) {
            this.Title = title;
            this.Description = description;
        }

        public string Title { get; set; }
        public string Description { get; set; }

        #region Implementation of IResponseService

        public ResponseMessageBase Handle(RequestMessageBase requestMessage) {
            var responseMessage = requestMessage.CreateVideoResponse(mediaId);
            responseMessage.Title = Title;
            responseMessage.Description = Description;
            return responseMessage;
        }

        #endregion

        #region Overrides of ResponseMedia

        protected override UploadMediaType MediaType {
            get { return UploadMediaType.Video; }
        }

        #endregion
    }
}
